package com.example.a2209_shop.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

object LoadImage {
    /**
     * 绑定适配器--加载图片
     */
    @BindingAdapter("img_url")
    @JvmStatic
    fun loadImage(imageView:ImageView,url:String?){
        if(url!=null){
            Glide.with(imageView.context).load(url).circleCrop().into(imageView)
        }
    }
    /**
     * 绑定适配器--加载轮播图
     */
    @BindingAdapter("banner_url")
    @JvmStatic
    fun loadBanner(banner: Banner,list: MutableList<String>?){
        if(list!=null){
            banner.setImageLoader(object :ImageLoader(){
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context != null&&imageView!=null) {
                        Glide.with(context).load(path).into(imageView)
                    }
                }
            })
            banner.update(list)
        }
    }


}